// pages/orderPage/orderPage.js
var app = getApp();
var api = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //全部
    order: [],
    //待付款
    orderNoPay: [],
    //待派单
    orderNoPai: [],
    //待完成
    orderNoFinish: [],
    //待评价
    orderNoPin: [],
    currentTab: 0,
    showNoPay: false,
    showNoPai: false,
    showNoFinish: false,
    showNoPing: false,
    userId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      userId: options.userId
    })
    var userId = wx.getStorageSync("userId");
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight
    })
    if (options.partnerUserId == undefined) {
      this.setData({
        partnerUserId: 0
      })
    } else {
      this.setData({
        partnerUserId: options.partnerUserId
      })
    }
    this.setData({
      type: options.type
    })
  },
  /**
   * 页面分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: that.data.title,
      imageUrl: "http://file.jwsxmall.com/shareImg.jpg",
      desc: '分享页面的内容',
      path: '/pages/myPage/myPage?partnerUserId=' + wx.getStorageSync("userId") + '&type=0', // 路径，传递参数到指定页面

    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var that = this;
    wx.request({
      url: app.globalData.url + "getAppUserBalanceHistoryList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        type: 0,
        userId: wx.getStorageSync("userId"),
        token: that.data.token
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          if (res.data.token != "" && res.data.token != undefined) {
            wx.setStorageSync("token", res.data.token)
          }
          that.setData({
            balance: data.data
          })
        }
        if (res.data.result == 9) {
          wx.reLaunch({
            url: '/pages/zcuslist/index',
          })
          return false;
        }
      },
      complete: function () {
        wx.hideLoading();
      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    that.setData({
      token: wx.getStorageSync("token")
    });
    api.authorization(0, that.data.partnerUserId);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },



  /**
   * 全部跳转到订单详情
   */
  toOrderDetail: function(res) {

    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderid=' + this.data.order[res.currentTarget.dataset.index].orderId,
    })
  },

  /**
   * 待付款跳转到订单详情
   */
  noPayToOrderDetail: function(res) {

    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderid=' + this.data.orderNoPay[res.currentTarget.dataset.index].orderId,
    })
  },

  /**
   * 待派单跳转到订单详情
   */
  noPaiToOrderDetail: function(res) {

    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderid=' + this.data.orderNoPai[res.currentTarget.dataset.index].orderId,
    })
  },

  /**
   * 待完成跳转到订单详情
   */
  noFinishToOrdeDetail: function(res) {

    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderid=' + this.data.orderNoFinish[res.currentTarget.dataset.index].orderId,
    })
  },

  /**
   * 待评价跳转到订单详情
   */
  noPinToOrderDetail: function(res) {

    wx.navigateTo({
      url: '/pages/orderDetail/orderDetail?orderid=' + this.data.orderNoPin[res.currentTarget.dataset.index].orderId,
    })
  },

  navBack: function () {
    wx.navigateBack({

    })
  }

})